package com.lottery.material.controller.portal.user;

import com.lottery.material.common.Constants;
import com.lottery.material.config.upload.UploadFileConfig;
import com.lottery.material.controller.base.BaseController;
import com.lottery.material.enumeration.ResultEnum;
import com.lottery.material.jedis.JedisClient;
import com.lottery.material.pojo.portaluser.FollowInfo;
import com.lottery.material.pojo.portaluser.PortalUserInfo;
import com.lottery.material.pojo.portaluser.ValidateCodeRecord;
import com.lottery.material.resolver.CustomException;
import com.lottery.material.service.portal.circle.CircleInfoService;
import com.lottery.material.service.portal.user.FollowInfoService;
import com.lottery.material.service.portal.user.PortalUserInfoService;
import com.lottery.material.service.portal.user.ValidateCodeRecordService;
import com.lottery.material.util.*;
import com.lottery.material.vo.portal.user.AccountAndSecurityVo;
import com.lottery.material.vo.portal.user.AuthenticationUserVo;
import com.lottery.material.vo.portal.user.FollowUserVo;
import com.lottery.material.vo.portal.user.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;

@Api(value = "前端用户接口", tags = { "前端用户接口" })
@Controller
@RequestMapping("/portal/user")
@Slf4j
public class PortalUserController extends BaseController {

    @Autowired
    @Qualifier("jedisClientCluster")
    private JedisClient jedisClient;

    @Autowired
    PortalUserInfoService portalUserInfoService;

    @Autowired
    ValidateCodeRecordService validateCodeRecordService;

    @Autowired
    FollowInfoService followInfoService;
    @Autowired
    CircleInfoService circleInfoService;
    @Autowired
    UploadFileConfig uploadFileConfig;


    @ApiOperation(value="获取验证码接口", notes="获取验证码接口（注册、登录、银行预留手机号、找回密码）")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "phoneNumber", value = "手机号", required = true, dataType = "String"),
        @ApiImplicitParam(name = "sendSource", value = "发送来源（1：注册；2：登录；3：绑定银行卡-银行预留手机号验证；4：找回密码）", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/getVerificationCode",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getVerificationCode(HttpServletRequest request) throws IOException {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }
        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        String phoneNumber = reqParamMap.get("phoneNumber");
        if (StringUtils.isBlank(phoneNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"phoneNumber"));
        }else if(!ParameterUtil.checkPhoneNumber(phoneNumber)){
            return ResponseResult.buildResult(ResultEnum.PHONENUMBER_ERROR);
        }else{
            PortalUserInfo portalUser = portalUserInfoService.findByLoginPhoneNumberAndUserStatusNot(phoneNumber,3);
            if(Objects.nonNull(portalUser) && portalUser.getUserStatus()==2){
                return ResponseResult.buildResult(ResultEnum.USER_FORBIDDEN);
            }
        }
        String sendSource = reqParamMap.get("sendSource");
        if (StringUtils.isBlank(sendSource)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"sendSource"));
        }

        ResponseResult result = portalUserInfoService.sendVerificationCode(reqParamMap);
        return result;
    }

    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="验证码校验接口", notes="验证码校验接口（注册、登录、银行预留手机号、找回密码）")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "phoneNumber", value = "手机号", required = true, dataType = "String"),
        @ApiImplicitParam(name = "validateCode", value = "验证码", required = true, dataType = "String")
    })
    @RequestMapping(value = "/verifyCode",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult verifyCode(HttpServletRequest request){
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        String phoneNumber = reqParamMap.get("phoneNumber");
        if (StringUtils.isBlank(phoneNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"phoneNumber"));
        }else if(!ParameterUtil.checkPhoneNumber(phoneNumber)){
            return ResponseResult.buildResult(ResultEnum.PHONENUMBER_ERROR);
        }

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        Map<String,String> map = new HashMap();
        ValidateCodeRecord byPhoneNumber = validateCodeRecordService.findFirstByPhoneNumberOrderByCreateTimeDesc(phoneNumber);
        if(Objects.nonNull(byPhoneNumber)){
            if(reqParamMap.get("validateCode").equals(byPhoneNumber.getValidateCode())){
                map.put("phoneNumber",phoneNumber);
                return ResponseResult.buildResult(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMessage(),map);
            }else {
                return ResponseResult.buildResult(ResultEnum.VALIDATECODEERROR_EXCEPTION.getCode(), ResultEnum.VALIDATECODEERROR_EXCEPTION.getMessage());

            }
        }else {
            return ResponseResult.buildResult(ResultEnum.VALIDATECODE_FAIL_EXCEPTION);
        }
    }

    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="注册接口", notes="用户使用手机号密码注册")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "phoneNumber", value = "手机号", required = true, dataType = "String"),
        @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String")
    })
    @RequestMapping(value = "/signUp",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult signUp(HttpServletRequest request) throws Exception {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        String phoneNumber = reqParamMap.get("phoneNumber");
        if (StringUtils.isBlank(phoneNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"phoneNumber"));
        }else if(!ParameterUtil.checkPhoneNumber(phoneNumber)){
            return ResponseResult.buildResult(ResultEnum.PHONENUMBER_ERROR);
        }
        String password = reqParamMap.get("password");
        if (StringUtils.isBlank(password)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"password"));
        }

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        PortalUserInfo portalUser = portalUserInfoService.findByLoginPhoneNumberAndUserStatusNot(phoneNumber,3);
        if(Objects.nonNull(portalUser)){
            return ResponseResult.buildResult(ResultEnum.PHONENUMBER_EXIST);
        }
        Map<String,String> map = portalUserInfoService.addUser(phoneNumber, password, reqParamMap.get("channelCode"));
        return ResponseResult.buildResult(200,"注册成功，请使用账号密码登录",map);
    }


    /**
     * description: 获取达人和圈子推荐信息
     * author sunny
     * createDate 2019-05-15 上午 9:28
     * @param request
     * @return
     */
    @RequestMapping(value = "/getRecommend",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getRecommend(HttpServletRequest request){
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap,jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        try {
            Map<String, Object> resultMap = new HashMap<>();
            List<Map<String, Object>> portalUsers = portalUserInfoService.findRecommendUser();
            resultMap.put("userRecommend", portalUsers);
            List<Map<String, Object>> circleInfos = circleInfoService.findHotCircle();
            resultMap.put("circleRecommend", circleInfos);
            return ResponseResult.buildResult(ResultEnum.GET_RECOMMEND_SUCCESS, resultMap);
        } catch (Exception e) {
            log.error("【获取达人和圈子推荐信息出现异常】:{}", ExceptionUtil.logExceptionStack(e));
            throw new CustomException(ResultEnum.GET_RECOMMEND_EXCEPTION);
        }
    }


    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="注册达人和圈子设置接口", notes="注册达人和圈子设置接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "masterUserIds", value = "达人用户id", required = true, dataType = "Array"),
            @ApiImplicitParam(name = "circleId", value = "圈子id", required = true, dataType = "Array")
    })
    @RequestMapping(value = "/watchExpertAndCircle",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult watchExpertAndCircle(HttpServletRequest request) {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        ParameterUtil.checkLogin(reqParamMap,jedisClient, portalUserInfoService);

        String userIds = reqParamMap.get("userIds");
        if (StringUtils.isBlank(userIds)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"userIds"));
        }
        String circleIds = reqParamMap.get("circleIds");
        if (StringUtils.isBlank(circleIds)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"circleIds"));
        }

        ResponseResult result = portalUserInfoService.editWatchRxpertAndCircle(userIds,circleIds,reqParamMap.get("userId"));
        return result;
    }

    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="前端用户登录接口", notes="用户使用手机号密码或者手机验证码登录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "loginPhoneNumber", value = "手机号", required = true, dataType = "String"),
        @ApiImplicitParam(name = "loginType", value = "登录类型", required = true, dataType = "String"),
        @ApiImplicitParam(name = "passwordOrCode", value = "密码或验证码", required = true, dataType = "String")
    })
    @RequestMapping(value = "/signIn",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult signIn(HttpServletRequest request) throws Exception {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }
        String loginPhoneNumber = reqParamMap.get("loginPhoneNumber");
        if (StringUtils.isBlank(loginPhoneNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"loginPhoneNumber"));
        }else if(!ParameterUtil.checkPhoneNumber(loginPhoneNumber)){
            return ResponseResult.buildResult(ResultEnum.PHONENUMBER_ERROR);
        }
        String loginType = reqParamMap.get("loginType");
        if (StringUtils.isBlank(loginType)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"loginType"));
        }
        String passwordOrCode = reqParamMap.get("passwordOrCode");
        if (StringUtils.isBlank(passwordOrCode)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"passwordOrCode"));
        }
        String channelCode = reqParamMap.get("channelCode");
        if (StringUtils.isBlank(channelCode)) {
            return ResponseResult.buildFormatResult(ResultEnum.PARAMETER_NOT_NULL, "channelCode");
        }

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        Map<String,String> map = new HashMap();
        PortalUserInfo portalUser = portalUserInfoService.findByLoginPhoneNumberAndUserStatusNot(loginPhoneNumber,3);
        //密码登录
        if("1".equals(loginType)){
            if(portalUser==null){
                return ResponseResult.buildResult(ResultEnum.USER_NOT_EXIST.getCode(),ResultEnum.USER_NOT_EXIST.getMessage());
            }
            if(portalUser.getUserStatus()==2){
                return ResponseResult.buildResult(ResultEnum.USER_FORBIDDEN);
            }
            if(!portalUser.getLoginPassword().equals(MD5Util.MD5(passwordOrCode))){
                return ResponseResult.buildResult(ResultEnum.PASSWORD_WRONG_ERROR);
            }
            signin(map, portalUser);
        }
        //短信验证码登录
        if("2".equals(loginType)){
            ValidateCodeRecord validateCodeRecord = validateCodeRecordService.findFirstByPhoneNumberOrderByCreateTimeDesc(loginPhoneNumber);
            if (!passwordOrCode.equals(validateCodeRecord)) {
                return ResponseResult.buildResult(ResultEnum.VALIDATECODEERROR_EXCEPTION);
            }

            if(portalUser==null){
                map = portalUserInfoService.addUser(loginPhoneNumber, null, channelCode);
                jedisClient.hset("portalUser",map.get("userId"), map.get("accessToken"));
            }else {
                signin(map, portalUser);
            }
        }
        return ResponseResult.buildResult(200,"登录成功",map);
    }

    private void signin(Map<String, String> map, PortalUserInfo portalUser) {
        map.put("userId",portalUser.getUserId());
        String accessToken = UUID.randomUUID().toString();
        map.put("accessToken",accessToken);
        jedisClient.hset("portalUser",portalUser.getUserId(),accessToken);
        portalUser.setAccessToken(accessToken);
        portalUserInfoService.updateByPrimaryKeySelective(portalUser);
    }


    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="重置密码接口", notes="重置密码")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "phoneNumber", value = "手机号", required = true, dataType = "String"),
        @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String")
    })
    @RequestMapping(value = "/updatePwd",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult updatePwd(HttpServletRequest request) {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }
        String phoneNumber = reqParamMap.get("phoneNumber");
        if (StringUtils.isBlank(phoneNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"phoneNumber"));
        }else if(!ParameterUtil.checkPhoneNumber(phoneNumber)){
            return ResponseResult.buildResult(ResultEnum.PHONENUMBER_ERROR);
        }

        String password = reqParamMap.get("password");
        if (StringUtils.isBlank(password)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"password"));
        }
        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        PortalUserInfo portalUser = portalUserInfoService.findByLoginPhoneNumberAndUserStatusNot(phoneNumber,3);
        if(!Objects.nonNull(portalUser)){
            return ResponseResult.buildResult(ResultEnum.USER_NOT_EXIST);
        }
        portalUser.setLoginPassword(MD5Util.MD5(password));
        portalUser.setAccessToken("");
        jedisClient.hdel("portalUser",portalUser.getUserId());
        portalUserInfoService.updateByPrimaryKeySelective(portalUser);
        return ResponseResult.buildResult(ResultEnum.SETTING_SUCCESS.getCode(), String.format(ResultEnum.SETTING_SUCCESS.getMessage(),"密码"));
    }

    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="个人用户中心接口", notes="根据userId查询用户信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String")
    })
    @RequestMapping(value = "/getMyUserInfo",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getMyUserInfo(HttpServletRequest request) {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        ParameterUtil.checkLogin(reqParamMap,jedisClient, portalUserInfoService);

        UserVo dto = portalUserInfoService.findMyPortalUserInfoDtoByUserId(reqParamMap.get("userId"));
        return ResponseResult.buildSuccess(dto);
    }

    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="他人用户中心-用户信息接口", notes="根据userId查询用户信息")
    @ApiImplicitParam(name = "hisUserId", value = "用户唯一标识", required = true)
    @RequestMapping(value = "/getPortalUserInfo" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getPortalUserInfo(HttpServletRequest request) {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }
        String hisUserId = reqParamMap.get("hisUserId");
        if (StringUtils.isBlank(hisUserId)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"hisUserId"));
        }
        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        Map<String,Object> portalUserInfo = portalUserInfoService.findPortalUserInfoDtoByUserId(hisUserId);

        if(StringUtils.isBlank(reqParamMap.get("userid"))){
            portalUserInfo.put("isFollow",1);
            return ResponseResult.buildSuccess(portalUserInfo);
        }else{
            FollowInfo followInfo = followInfoService.findByUserIdAndFollowUserId(reqParamMap.get("userId"), hisUserId);
            if(Objects.nonNull(followInfo)){
                portalUserInfo.put("isFollow",2);
            }else{
                portalUserInfo.put("isFollow",1);
            }
            return ResponseResult.buildSuccess(portalUserInfo);
        }
    }

    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="修改个人资料接口", notes="修改个人资料接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "modifyType", value = "修改类型（1：头像；2：昵称；3；个性签名）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "userIcon", value = "用户头像", required = true, dataType = "String"),
        @ApiImplicitParam(name = "nickName", value = "昵称", required = true, dataType = "String"),
        @ApiImplicitParam(name = "signature", value = "个性签名", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/updatePortalUserInfo" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult updatePortalUserInfo(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap,jedisClient, portalUserInfoService);

        PortalUserInfo portalUserInfo = new PortalUserInfo();
        String modifyType = reqParamMap.get("modifyType");
        if (StringUtils.isBlank(modifyType)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"modifyType"));
        }
        if("1".equals(modifyType)){
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            List<MultipartFile> multipartFiles = multipartRequest.getFiles("pics");
            if(multipartFiles == null || multipartFiles.size() == 0){
                return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"pics"));
            }
            String picUrl = OSSClientUtil.uploadFile(uploadFileConfig, multipartFiles.get(0), uploadFileConfig.getPortalUserInfoModuleName());
            portalUserInfo.setUserIcon(picUrl);
        }
        if("2".equals(modifyType)){
            String nickName = reqParamMap.get("nickName");
            if (StringUtils.isBlank(nickName)) {
                return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"nickName"));
            }else{
                List<String> nickNameList = jedisClient.lrange(Constants.USER_NICK_NAME, 0, jedisClient.llen(Constants.USER_NICK_NAME));
                if(nickNameList.contains(nickName)){
                    return ResponseResult.buildResult(ResultEnum.NICK_NAME_EXIST);
                }
            }
            portalUserInfo.setNickName(nickName);
            portalUserInfo.setIsUpdateNickName(2);
        }
        if("3".equals(modifyType)){
            String signature = reqParamMap.get("signature");
            if (StringUtils.isBlank(signature)) {
                return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"Signature"));
            }
            portalUserInfo.setSignature(signature);
        }
        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;
        portalUserInfo.setUserId(reqParamMap.get("userId"));
        PortalUserInfo userInfo = portalUserInfoService.findByUserId(reqParamMap.get("userId"));
        portalUserInfo.setId(userInfo.getId());
        Integer i = portalUserInfoService.updateByPrimaryKeySelective(portalUserInfo);
        if(i == 1){
            if("1".equals(modifyType)){
                return ResponseResult.buildResult(ResultEnum.UPDATE_SUCCESS, portalUserInfo.getUserIcon());
            }else {
                if ("2".equals(modifyType)) {
                    jedisClient.lrem(Constants.USER_NICK_NAME, 0, userInfo.getNickName());
                    jedisClient.lpush(Constants.USER_NICK_NAME, reqParamMap.get("nickName"));
                }
                return ResponseResult.buildResult(ResultEnum.UPDATE_SUCCESS);
            }
        }else {
            return ResponseResult.buildResult(ResultEnum.UPDATE_FAIL);
        }
    }

    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="关注/粉丝列表接口", notes="关注/粉丝列表接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "interfaceType", value = "接口类型（1：关注；2：粉丝）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "page", value = "用于分页", required = true, dataType = "String")
    })
    @RequestMapping(value = "/getFollowUserList" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getFollowUserList(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);


        List<FollowUserVo> userVos = null;

        String interfaceType = reqParamMap.get("interfaceType");
        if (StringUtils.isBlank(interfaceType)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"interfaceType"));
        }

        String page = reqParamMap.get("page");
        if (StringUtils.isBlank(page)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"page"));
        }

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        if("1".equals(interfaceType)){
            userVos = portalUserInfoService.findFollowUserListByUserId(reqParamMap.get("userId"),Integer.valueOf(page));
        }
        if("2".equals(interfaceType)){
            userVos = portalUserInfoService.findFansUserListByUserId(reqParamMap.get("userId"),Integer.valueOf(page));
        }
        return ResponseResult.buildSuccess(userVos);
    }


    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="我的财富列表接口", notes="关注/粉丝列表接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/getMyTreasure" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult getMyTreasure(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }
        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        Map<String,Object> myTreasure = portalUserInfoService.findMyTreasure(reqParamMap.get("userId"));
        return ResponseResult.buildSuccess(myTreasure);
    }


    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="充值页面接口", notes="充值页面接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/goToRecharge" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult goToRecharge(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        Map<String,Object> rechargeList = portalUserInfoService.findRechargeList(reqParamMap.get("userId"));

        return ResponseResult.buildSuccess(rechargeList);
    }

    @ApiOperation(value="常规认证验证接口", notes="常规认证验证接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/checkAuthentication" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult checkAuthentication(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;
        AuthenticationUserVo userVo = portalUserInfoService.findUserAuthentication(reqParamMap.get("userId"));
        return ResponseResult.buildSuccess(userVo);
    }


    @ApiOperation(value="常规认证确认接口", notes="常规认证确认接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/confirmAuthentication" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult confirmAuthentication(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;
        ResponseResult result = portalUserInfoService.confirmAuthentication(reqParamMap.get("userId"));
        return result;
    }

    @ApiOperation(value="账号与安全接口", notes="账号与安全接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/AccountAndSecurity" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult AccountAndSecurity(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        AccountAndSecurityVo result = portalUserInfoService.findAccountAndSecurity(reqParamMap.get("userId"));
        return ResponseResult.buildSuccess(result);
    }


    /**
     * @Author 焦阳
     * @param request
     * @return
     */
    @ApiOperation(value="设置/修改密码接口", notes="设置/修改密码接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "actionType", value = "功能类型（1：设置密码；2：修改密码；）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "newPassword", value = "设置的新密码", required = true, dataType = "String"),
        @ApiImplicitParam(name = "oldPassword", value = "旧密码", required = true, dataType = "String")
    })
    @RequestMapping(value = "/setNewPassword",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult setNewPassword(HttpServletRequest request) {
        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;


        String actionType = reqParamMap.get("actionType");
        if (StringUtils.isBlank(actionType)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"actionType"));
        }
        String newPassword = reqParamMap.get("newPassword");
        if (StringUtils.isBlank(newPassword)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"newPassword"));
        }
        String oldPassword = reqParamMap.get("oldPassword");
        if("2".equals(actionType)){
            if (StringUtils.isBlank(oldPassword)) {
                return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"oldPassword"));
            }
        }


        PortalUserInfo portalUser = portalUserInfoService.findByUserId(reqParamMap.get("userId"));
        if(!Objects.nonNull(portalUser)){
            return ResponseResult.buildResult(ResultEnum.USER_NOT_EXIST);
        }

        //旧密码错误
        if("2".equals(actionType)){
            if(!MD5Util.MD5(oldPassword).equals(portalUser.getLoginPassword())){
                return ResponseResult.buildResult(ResultEnum.OLDPASSWORD_WRONG_ERROR);
            }
        }
        //新密码与旧密码相同
        if(MD5Util.MD5(newPassword).equals(portalUser.getLoginPassword())){
            return ResponseResult.buildResult(ResultEnum.SAME_PASSWORD);
        }

        portalUser.setLoginPassword(MD5Util.MD5(newPassword));
        portalUser.setAccessToken("");
        jedisClient.hdel("portalUser",portalUser.getUserId());
        Integer i = portalUserInfoService.updateByPrimaryKeySelective(portalUser);
        if(i==1&&"2".equals(actionType)){
            return ResponseResult.buildResult(ResultEnum.UPDATE_SUCCESS.getCode(), String.format(ResultEnum.UPDATE_SUCCESS.getMessage(),"密码"));
        }else if(i==1&&"1".equals(actionType)){
            return ResponseResult.buildResult(ResultEnum.SETTING_SUCCESS.getCode(), String.format(ResultEnum.SETTING_SUCCESS.getMessage(),"密码"));
        }else{
            return ResponseResult.buildResult(ResultEnum.UPDATE_FAIL);
        }
    }


    @ApiOperation(value="实名认证提交接口", notes="实名认证提交接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "realName", value = "真实姓名", required = true, dataType = "String"),
        @ApiImplicitParam(name = "idNumber", value = "身份证号", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/submitRealNameAuthentication" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult submitRealNameAuthentication(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;
        String realName = reqParamMap.get("realName");
        if (StringUtils.isBlank(realName)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"realName"));
        }
        String idNumber = reqParamMap.get("idNumber");
        if (StringUtils.isBlank(idNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"idNumber"));
        }
        if(!IDCardUtil.validateCard(idNumber)){
            return ResponseResult.buildResult(ResultEnum.IDNUMBER_WRONG);
        };
        PortalUserInfo portalUser = portalUserInfoService.findByUserId(reqParamMap.get("userId"));
        portalUser.setIdNumber(idNumber);
        portalUser.setRealName(realName);
        Integer i = portalUserInfoService.updateByPrimaryKeySelective(portalUser);
        if(i==1){
            return ResponseResult.buildResult(ResultEnum.REALNAME_AUTH_SUCCESS);
        }else{
            return ResponseResult.buildResult(ResultEnum.REALNAME_AUTH_FAIL);
        }
    }

    @ApiOperation(value="设置/验证银行卡验证密码接口", notes="设置/验证银行卡验证密码接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "actionType", value = "功能类型（1：设置；2：验证）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "confirmPassword", value = "确认密码", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/setOrAuthBankCard" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult setOrAuthBankCard(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        String actionType = reqParamMap.get("actionType");
        if (StringUtils.isBlank(actionType)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"actionType"));
        }
        String confirmPassword = reqParamMap.get("confirmPassword");
        if (StringUtils.isBlank(confirmPassword)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"confirmPassword"));
        }

        PortalUserInfo portalUser = portalUserInfoService.findByUserId(reqParamMap.get("userId"));
        if("1".equals(actionType)){
            portalUser.setBankCardCheckPassword(confirmPassword);
            Integer i = portalUserInfoService.updateByPrimaryKeySelective(portalUser);
            if(i==1){
                return ResponseResult.buildResult(ResultEnum.SETTING_SUCCESS.getCode(), String.format(ResultEnum.SETTING_SUCCESS.getMessage(),""));
            }else{
                return ResponseResult.buildResult(ResultEnum.SETTING_FAIL);
            }
        }else if("2".equals(actionType)){
            if(confirmPassword.equals(portalUser.getBankCardCheckPassword())){
                return ResponseResult.buildResult(ResultEnum.VALIDATECODE_SUCCESS);
            }else{
                return ResponseResult.buildResult(ResultEnum.VALIDATECODE_FAIL_EXCEPTION);
            }

        }else{
            return ResponseResult.buildResult(ResultEnum.PARAMETER_ERROR.getCode(), String.format(ResultEnum.PARAMETER_ERROR.getMessage(),"actionType"));
        }
    }

    @ApiOperation(value="忘记银行卡验证密码-验证接口", notes="忘记银行卡验证密码-验证接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "realName", value = "真实姓名", required = true, dataType = "String"),
        @ApiImplicitParam(name = "idNumber", value = "身份证号", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/forgetBankCardCheckPwd" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult forgetBankCardCheckPwd(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        String realName = reqParamMap.get("realName");
        if (StringUtils.isBlank(realName)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"realName"));
        }
        String idNumber = reqParamMap.get("idNumber");
        if (StringUtils.isBlank(idNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"idNumber"));
        }

        if(!IDCardUtil.validateCard(idNumber)){
            return ResponseResult.buildResult(ResultEnum.IDNUMBER_WRONG);
        };

        PortalUserInfo portalUser = portalUserInfoService.findByUserId(reqParamMap.get("userId"));
        //验证成功
        if(realName.equals(portalUser.getRealName())&&idNumber.equals(portalUser.getIdNumber())){
            return ResponseResult.buildResult(ResultEnum.VALIDATECODE_SUCCESS);
        }else{
            return ResponseResult.buildResult(ResultEnum.VALIDATECODE_FAIL_EXCEPTION);
        }
    }


    @ApiOperation(value="绑定银行卡提交接口", notes="绑定银行卡提交接口")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "userId", value = "用户唯一标识（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "accessToken", value = "访问令牌（登录的用户必传）", required = true, dataType = "String"),
        @ApiImplicitParam(name = "bankCardName", value = "银行卡持卡人姓名", required = true, dataType = "String"),
        @ApiImplicitParam(name = "bankCardNumber", value = "银行卡卡号", required = true, dataType = "String"),
        @ApiImplicitParam(name = "bankCode", value = "开户银行编号", required = true, dataType = "String"),
        @ApiImplicitParam(name = "province", value = "省", required = true, dataType = "String"),
        @ApiImplicitParam(name = "city", value = "市", required = true, dataType = "String"),
        @ApiImplicitParam(name = "district", value = "区", required = true, dataType = "String"),
        @ApiImplicitParam(name = "bankSubBranch", value = "银行支行", required = true, dataType = "String"),
        @ApiImplicitParam(name = "bankPhoneNumber", value = "银行预留手机号", required = true, dataType = "String"),
    })
    @RequestMapping(value = "/bindBankCardSubmit" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult bindBankCardSubmit(HttpServletRequest request) {

        Map<String, String> reqParamMap = new HashMap<>();
        //解析参数
        if (ParameterUtil.analyticParameter(request, reqParamMap)) {
            throw new CustomException(ResultEnum.PARSE_EXCEPTION);
        }

        //非空判断
        ResponseResult respDate = validateEmpty(reqParamMap);
        if (null != respDate) {
            return respDate;
        }

        ParameterUtil.checkLogin(reqParamMap, jedisClient, portalUserInfoService);

        ResponseResult x = ParameterUtil.checkSign(reqParamMap);
        if (x != null) return x;

        String bankCardName = reqParamMap.get("bankCardName");
        if (StringUtils.isBlank(bankCardName)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"bankCardName"));
        }
        String bankCardNumber = reqParamMap.get("bankCardNumber");
        if (StringUtils.isBlank(bankCardNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"bankCardNumber"));
        }
        String bankCode = reqParamMap.get("bankCode");
        if (StringUtils.isBlank(bankCode)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"bankCode"));
        }
        String bankPhoneNumber = reqParamMap.get("bankPhoneNumber");
        if (StringUtils.isBlank(bankPhoneNumber)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"bankPhoneNumber"));
        }
        String province = reqParamMap.get("province");
        if (StringUtils.isBlank(province)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"province"));
        }
        String city = reqParamMap.get("city");
        if (StringUtils.isBlank(city)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"city"));
        }
        String district = reqParamMap.get("district");
        if (StringUtils.isBlank(district)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"district"));
        }
        String bankSubBranch = reqParamMap.get("bankSubBranch");
        if (StringUtils.isBlank(bankSubBranch)) {
            return ResponseResult.buildResult(ResultEnum.PARAMETER_BLANK_ERROR.getCode(), String.format(ResultEnum.PARAMETER_BLANK_ERROR.getMessage(),"bankSubBranch"));
        }

        if(!BankCardUtil.checkBankCard(bankCardNumber)){
            log.error("银行卡号：" + bankCardNumber + "  check code: " + BankCardUtil.getBankCardCheckCode(bankCardNumber.substring(0, bankCardNumber.length() - 1))
                    + " 是否为银行卡: " + BankCardUtil.checkBankCard(bankCardNumber) + " 卡种：" + BankCardUtil.getNameOfBank(bankCardNumber));
            return ResponseResult.buildResult(ResultEnum.BANKCARD_WRONG);
        };


        if(!ParameterUtil.checkPhoneNumber(bankPhoneNumber)){
            return ResponseResult.buildResult(ResultEnum.PHONENUMBER_ERROR);
        }

        PortalUserInfo portalUser = portalUserInfoService.findByUserId(reqParamMap.get("userId"));
        portalUser.setBankCardName(bankCardName);
        portalUser.setBankCardNumber(bankCardNumber);
        portalUser.setBankCode(bankCode);
        portalUser.setBankPhoneNumber(bankPhoneNumber);
        portalUser.setProvince(province);
        portalUser.setCity(city);
        portalUser.setDistrict(district);
        portalUser.setBankSubBranch(bankSubBranch);
        Integer i = portalUserInfoService.updateByPrimaryKeySelective(portalUser);
        //提交成功
        if(i==1){
            return ResponseResult.buildResult(ResultEnum.SUCCESS);
        }else{
            return ResponseResult.buildResult(ResultEnum.SUBMIT_FAIL);//提交失败
        }
    }

}
